package java2020spring;
import java.awt.*;
import javax.swing.*;
public class FishCalculator extends JFrame{
	public FishCalculator() {
		Container c = getContentPane();
		setTitle("FishCalculator");
		c.setBackground(Color.BLACK);
		setSize(315, 410);
		setResizable(false);
		setLocationRelativeTo(null);
		setLayout(null);
		JTextField ctf = this.calculatorTextField();
		this.NumberAndCharacter(ctf);
		setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
		setVisible(true);
	}
	private void NumberAndCharacter(JTextField ctf){//数字与运算符
		JPanel ncp = new JPanel();
		ncp.setBounds(8,80,300,300);
		ncp.setBackground(new Color(140,88,50));
		ncp.setBorder(BorderFactory.createLoweredBevelBorder());
		ncp.setLayout(new GridLayout(7,4,1,1));
		JButton ncButton[] = new JButton[28];
		String[] nc = {
				       "1/x","lnx","lgx","cbrt",
				       "√","x²","x³","e^a",
				       "AC","+/-","%","÷",
				       "7","8","9","x",
	                   "4","5","6","-",
	                   "1","2","3","+",
	                   "0","00",".","="};
		CalculatorListener mouse = new CalculatorListener(ctf);
		for(int i =0;i<ncButton.length;i++) {
			ncButton[i]=new JButton(nc[i]);
			ncButton[i].setFont(new Font("微软雅黑", 0, 20));
			ncp.add(ncButton[i]);
			ncButton[i].addActionListener(mouse);
		}
		this.add(ncp);
	}
	
	private JTextField calculatorTextField(){//运算区域
		JPanel textPanel = new JPanel();
		textPanel.setBounds(8,10,300,50);
		textPanel.setBackground(new Color(140,88,50));
		textPanel.setBorder(BorderFactory.createLoweredBevelBorder());
		JTextField ctf = new JTextField(14);
		ctf.setHorizontalAlignment(JTextField.RIGHT);
		ctf.setForeground(Color.BLACK);
		ctf.setBackground(new Color(140,88,50));
	    ctf.setBorder(null);
		ctf.setFont(new Font("微软雅黑",Font.PLAIN,20));
		ctf.setEditable(false);
		ctf.setText("0");
		textPanel.add(ctf);
		this.add(textPanel);
		return ctf;
	}
	public static void main(String[] args) {
		new FishCalculator();
	}
}
